/**
 * @param {number[]} customers
 * @param {number} boardingCost
 * @param {number} runningCost
 * @return {number}
 */
var minOperationsMaxProfit = function (customers, boardingCost, runningCost) {
  let round = 1,
    remind = 0
  let profile = 0
  for (let i = 0; i < customers.length; i++) {
    let people = customers[i] + remind
    if (people >= 4) {
      people -= 4
      round++
      profile += 4 * boardingCost - runningCost
    }
    remind = people
  }

  while (remind > 0) {
    profile += remind * boardingCost - Math.ceil(remind / 4) * runningCost
    remind=0
  }

  if ((round + 1) % 4 > 0) {
    profile -= (3 - (round % 4)) * runningCost
    
  }
  return profile
}
console.log(minOperationsMaxProfit([8, 3], 5, 6));

